home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / esc.jar / com / extensibility / xml / RELAXWriter.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-06-30  |  6.7 KB  |  196 lines

  1. package com.extensibility.xml;
  2.  
  3. import com.extensibility.xml.dt.DataTypeFactory;
  4. import com.extensibility.xml.dt.DataTypeIntf;
  5. import java.util.Enumeration;
  6.  
  7. public class RELAXWriter extends SchemaWriter {
  8.    ElemProxy elemProxy = new ElemProxy(this);
  9.    PEntityProxy pEntityProxy = new PEntityProxy(this);
  10.  
  11.    public RELAXWriter(SchemaIntf var1) {
  12.       super(var1, var1.getURI());
  13.    }
  14.  
  15.    public RELAXWriter(SchemaIntf var1, URI var2) {
  16.       super(var1, var2);
  17.    }
  18.  
  19.    public void writeAnnotation(SXE var1, Enumeration var2) {
  20.       if (var2 != null && var2.hasMoreElements()) {
  21.          var1.writeElem("annotation", -1);
  22.  
  23.          while(var2.hasMoreElements()) {
  24.             Comment var3 = (Comment)var2.nextElement();
  25.             var1.writeElem("documentation", -1);
  26.             if (var3.getKind().length() > 0) {
  27.                var1.writeAttr("usage", var3.getKind());
  28.             }
  29.  
  30.             var1.writeText(var3.getComment(true));
  31.             var1.flush("documentation");
  32.          }
  33.  
  34.          var1.flush("annotation");
  35.       }
  36.    }
  37.  
  38.    void writeDataTypeAttr(SXE var1, DataTypeIntf var2) {
  39.       if (var2 == null) {
  40.          var2 = DataTypeFactory.createDataType(DataTypeIntf.STRING);
  41.       }
  42.  
  43.       String var3 = BaseFlavor.getSourceCode("xsd", ((DataTypeIntf)var2).getSource());
  44.       if (var3 != null) {
  45.          var1.writeAttr("type", var3);
  46.       }
  47.  
  48.    }
  49.  
  50.    public void writeDataTypeFacets(SXE var1, BaseDeclaration var2, DataTypeIntf var3) {
  51.       if (var3 != null) {
  52.          XSDLWriter.writeDataTypeFacets(var1, var2, var3);
  53.       }
  54.  
  55.    }
  56.  
  57.    public void writeModel(SXE var1, boolean var2, ContentModel var3) {
  58.       ContentModelTerm var4 = var3.getRootGroup();
  59.       if (var4 == null) {
  60.          ContentModelTermEnum var5 = ((ContentModelTerm)var3).getTerms(false);
  61.  
  62.          while(var5.hasMoreElements()) {
  63.             this.writeParticle(var1, var2, (ContentModelTerm)var5.nextElement());
  64.          }
  65.       } else if (var4.getOwner() != var3.getOwner()) {
  66.          var1.writeElem("hedgeRef", -1, true);
  67.          var1.writeAttr("label", var4.getOwner().getName());
  68.       } else {
  69.          this.writeParticle(var1, var2, var4);
  70.       }
  71.  
  72.    }
  73.  
  74.    public void writeParticle(SXE var1, boolean var2, ContentModelTerm var3) {
  75.       if (var3 != null) {
  76.          if (var3.isOwned()) {
  77.             var1.writeElem("hedgeRef", -1, true);
  78.             var1.writeAttr("label", var3.getOwner().getName());
  79.          } else if (var3.isOccuranceOnly()) {
  80.             ContentModelTerm var4 = var3.firstTerm();
  81.             var1.writeElem("hedgeRef", -1, true);
  82.             var1.writeAttr("label", var4.getOwner().getName());
  83.             if (var3.getOccurance() != 0) {
  84.                var1.writeAttr("occurs", var3.getOccuranceAsString(true, false));
  85.             }
  86.          } else if (var3.isGroup()) {
  87.             String var6 = var3.isSeq() ? "sequence" : "choice";
  88.             var1.writeElem(var6, -1);
  89.             if (var3.getOccurance() != 0) {
  90.                var1.writeAttr("occurs", var3.getOccuranceAsString(true, false));
  91.             }
  92.  
  93.             ContentModelTermEnum var5 = var3.getTerms(false);
  94.  
  95.             while(var5.hasMoreElements()) {
  96.                this.writeParticle(var1, var2, (ContentModelTerm)var5.nextElement());
  97.             }
  98.  
  99.             var1.flush(var6);
  100.          } else if (!var3.isPCDATATerm()) {
  101.             var1.writeElem("ref", -1, true);
  102.             var1.writeAttr("label", var3.getTerm());
  103.             if (var3.getOccurance() != 0) {
  104.                var1.writeAttr("occurs", var3.getOccuranceAsString(true, false));
  105.             }
  106.          }
  107.  
  108.       }
  109.    }
  110.  
  111.    public void writeClauseBody(SXE var1, boolean var2, AttributeDeclaration.Owner var3) {
  112.       Enumeration var4 = var3.getAttributeGroup().getAttributes(false);
  113.  
  114.       while(var4.hasMoreElements()) {
  115.          AttributeGroupMember var5 = (AttributeGroupMember)var4.nextElement();
  116.          if (var5 instanceof AttributeGroup) {
  117.             this.writeAttributeRef(var1, (AttributeGroup)var5);
  118.          }
  119.       }
  120.  
  121.       var4 = var3.getAttributeGroup().getAttributes(false);
  122.  
  123.       while(var4.hasMoreElements()) {
  124.          AttributeGroupMember var7 = (AttributeGroupMember)var4.nextElement();
  125.          if (var7 instanceof AttributeDeclaration) {
  126.             this.writeAttribute(var1, var2, (AttributeDeclaration)var7);
  127.          }
  128.       }
  129.  
  130.    }
  131.  
  132.    public void writeAttributeRef(SXE var1, AttributeGroup var2) {
  133.       var1.writeElem("ref", -1, true);
  134.       var1.writeAttr("role", var2.getName());
  135.    }
  136.  
  137.    public void writeAttribute(SXE var1, boolean var2, AttributeDeclaration var3) {
  138.       var1.writeElem("attribute", -1);
  139.       var1.writeAttr("name", ((BaseDeclaration)var3).getName());
  140.       if (var3.getRequired()) {
  141.          var1.writeAttr("required", "true");
  142.       }
  143.  
  144.       this.writeDataTypeAttr(var1, var3.getDataType());
  145.       if (var2) {
  146.          this.writeAnnotation(var1, ((BaseDeclaration)var3).getComments());
  147.       }
  148.  
  149.       this.writeDataTypeFacets(var1, var3, var3.getDataType());
  150.       var1.flush("attribute");
  151.    }
  152.  
  153.    protected SchemaWriter.DeclWriterProxyIntf createProxy(ElementDeclaration var1) {
  154.       this.elemProxy.setDecl(var1);
  155.       return this.elemProxy;
  156.    }
  157.  
  158.    protected SchemaWriter.DeclWriterProxyIntf createProxy(ParameterEntityDeclaration var1) {
  159.       this.pEntityProxy.setDecl(var1);
  160.       return this.pEntityProxy;
  161.    }
  162.  
  163.    protected void writeHeader(SXE var1) {
  164.       var1.writeComment("Generated by XML Authority. ");
  165.       var1.writeElem("module", -1);
  166.       var1.writeAttr("moduleVersion", "1.2");
  167.       var1.writeLineBreak();
  168.       var1.writeAttr("relaxCore", "1.0");
  169.       var1.writeLineBreak();
  170.       URI var2 = super.schema.getNamespace();
  171.       String var3 = var2 == null ? super.schema.getURI().getFullName() : var2.toSource();
  172.       var1.writeAttr("targetNamespace", var3);
  173.       var1.writeLineBreak();
  174.       var1.writeAttr("xmlns", "http://www.xml.gr.jp/xmlns/relaxCore");
  175.       var1.writeElem("interface", -1);
  176.       String var4 = SchemaUtilities.getBestRootName(super.schema);
  177.       if (var4 != null) {
  178.          var1.writeElem("export", -1, true);
  179.          var1.writeAttr("label", var4);
  180.       }
  181.  
  182.       var1.flush("interface");
  183.    }
  184.  
  185.    protected void writeSchemaComments(SXE var1) {
  186.       Enumeration var2 = super.schema.getComments();
  187.       this.writeAnnotation(var1, var2);
  188.    }
  189.  
  190.    protected void writeIncludes(SXE var1, Enumeration var2) {
  191.    }
  192.  
  193.    protected void writeNamespaces(SXE var1, Enumeration var2) {
  194.    }
  195. }
  196.